package cn.hongwei.eduservice.controller.admin;

import cn.hongwei.eduservice.entity.Subject;
import cn.hongwei.eduservice.service.SubjectService;
import cn.hongwei.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author Great
 * @email 1224028994@qq.com
 * 讲师课程发布和管理
 */
@CrossOrigin
@RestController
@RequestMapping("/admin/edu/subject")
public class AdminSubjectController {

    @Autowired
    SubjectService subjectService;

    //导入
    @PostMapping("/import")
    public R importSubjects(MultipartFile file){
        subjectService.importSubjects(file);
        return R.ok();
    }

    //2、查询 一级分类 和它的子集合
    @GetMapping("/getSubjectsNestedList")
    public R getSubjectsNestedList(){
        // 每个一级分类 都提供一个子分类的集合  存储自己的下一级的分类
        List<Subject> parentSubjects = subjectService.getSubjectsNestedList();

        return R.ok().data("items" , parentSubjects);
    }

}
